import maya.cmds as mc

class LZ_attribute():
    def __init__(self):
        pass
    def lockAttr(self,obj = '' ,attr =['']):


        for at in attr:

                mc.setAttr(obj+'.'+ at, lock=True ,keyable = False ,channelBox = False)
                
    def unlockAttr(self , obj = '' ,attr =[''] ):
        for at in attr:

                mc.setAttr(obj+'.'+ at, lock=False ,keyable = True , channelBox = True )
                mc.setAttr(obj+'.'+ at, lock=False ,keyable = True  )
    
    
    def addAttrs(self,objname=[''],attrname='fuck',dv=0,key=1):
        if objname==None:
            objs=mc.ls(sl=True)
        if objname!=None:
            objs=objname
            
        for i in objs:
    
            mc.addAttr(i,longName=attrname,defaultValue=dv,k=1)
            if key == 0:
                mc.setAttr(str(i)+'.'+attrname,l=True)
                
    def addStringAttr(self , obj = '', attrName = '' , textinput = '' , edit = 0 ):
        
        if edit == 0:
        
            mc.addAttr( str(obj)  , ln =  attrName , dt = 'string' )
        
        mc.setAttr( str(obj) + '.' + str(attrName) ,  textinput, type = 'string'  )
        
        
        
        
        
    def FG_addAttrs(self,objname=[''],attrname='fuck',dv=0,key=1,minValue=0,maxValue=1):
        if objname==None:
            objs=mc.ls(sl=True)
        if objname!=None:
            objs=objname
            
        for i in objs:
    
            mc.addAttr(i,longName=attrname,defaultValue=dv,k=1)
            if key == 0:
                mc.setAttr(str(i)+'.'+attrname,l=True)
            
            if minValue != None:
                mc.addAttr(str(i)+'.'+attrname,e=True,min=minValue)
            if maxValue != None:
                mc.addAttr(str(i)+'.'+attrname,e=True,max=maxValue)
    def resetAllAttrs(self,ctrl_obj = ''):
        
        all_attrs = mc.listAttr( ctrl_obj , k =True)
        baseAttr = ['translateX','translateY','translateZ','rotateX','rotateY','rotateZ']
        basescale = ['scaleX','scaleY','scaleZ']
        vis = ['visibility']
        #jointRadius = []
        
        for at in all_attrs:
            if at in baseAttr:
                mc.setAttr( str(ctrl_obj)+'.'+str(at) , 0 )
            elif at in basescale:
                mc.setAttr( str(ctrl_obj)+'.'+str(at) , 1 )
            elif at in vis:  
                mc.setAttr( str(ctrl_obj)+'.'+str(at) , 1 )
            else:
                dvValue = mc.addAttr( str(ctrl_obj)+'.'+str(at) , q=True ,dv = True)
                mc.setAttr( str(ctrl_obj)+'.'+str(at) , dvValue )

    
    #----------------------   add attribute (enum) ------------------------------    
    def addEnumAttr(self,objname=['nurbsSphere1'],attrname='fuck',enumMember='fuck:',key=0):
        if objname==None:
            objs=mc.ls(sl=True)
        if objname!=None:
            objs=objname
            
        for i in objs:
            mc.addAttr(i,longName=attrname,at='enum',en=enumMember,k=1)
            if key == 0:
                mc.setAttr(str(i)+'.'+attrname,l=True)
                
                
                
    def find_defluatValue(self ,  obj  = 'xxxx'  ,attr = '' ):
        
        baseZeroAttr = ['tx','ty','tz','rx','ry','rz','translateX','translateY','translateZ','rotateX','rotateY','rotateZ' ]
        base_1_Attr = [ 'sx','sy','sz','v' ,'scaleX','scaleY','scaleZ','visibility'  ]
        
        definedAttr = mc.listAttr( obj , userDefined =True)
        keyableAttr = mc.listAttr( obj , k =True)
        
        
        
        if attr in baseZeroAttr:
            
            daf_value = 0 
        elif attr in base_1_Attr:
        
            mc.setAttr( str(obj)+'.'+str(attr) , 1 )
            daf_value = 1
        
        else:
            
            daf_value = mc.addAttr( str(obj)+'.'+str(attr)  ,q=True ,dv=True )
            
            
        return daf_value 
        
        
    def list_minMax_attrValue(self , obj = '' ,attr = ''):

        passAttr = [ 'v','visibility' ,'radius' ]
        
        min =  False
        max = False
        
        if attr in passAttr :
            
            pass
            
        else:
            
            if attr in [ 'tx' ,'translateX'  ]:
        
                
                if_limit = mc.transformLimits( obj ,q = True, etx = True )
                
                value_limit = mc.transformLimits( obj ,q = True, tx = True )
               
                if if_limit[0] ==True :
                     
                    min = value_limit[0]
                    
                else:
                    pass
                    
                if if_limit[1] ==True :
                     
                    max = value_limit[1]
                    
                else:
                    pass
                    
            #---------------------------------------
            elif attr in [ 'ty' ,'translateY'  ]:
        
                if_limit = mc.transformLimits( obj ,q = True, ety = True )
                
                value_limit = mc.transformLimits( obj ,q = True, ty = True )
                
                if if_limit[0] ==True :
                     
                    min = value_limit[0]
                    
                else:
                    pass
                    
                if if_limit[1] ==True :
                     
                    max = value_limit[1]
                    
                else:
                    pass
                    
            #---------------------------------------
            #---------------------------------------
            elif attr in [ 'tz' ,'translateZ'  ]:
        
                if_limit = mc.transformLimits( obj ,q = True, etz = True )
                
                value_limit = mc.transformLimits( obj ,q = True, tz = True )
                
                if if_limit[0] ==True :
                     
                    min = value_limit[0]
                    
                else:
                    pass
                    
                if if_limit[1] ==True :
                     
                    max = value_limit[1]
                    
                else:
                    pass
                    
            #---------------------------------------
            elif attr in [ 'rx' ,'rotateX'  ]:
        
                if_limit = mc.transformLimits( obj ,q = True, erx = True )
                
                value_limit = mc.transformLimits( obj ,q = True, rx = True )
                
                if if_limit[0] ==True :
                     
                    min = value_limit[0]
                    
                else:
                    pass
                    
                if if_limit[1] ==True :
                     
                    max = value_limit[1]
                    
                else:
                    pass
                    
            #---------------------------------------
            elif attr in [ 'ry' ,'rotateY'  ]:
        
                if_limit = mc.transformLimits( obj ,q = True, ery = True )
                
                value_limit = mc.transformLimits( obj ,q = True, ry = True )
                
                if if_limit[0] ==True :
                     
                    min = value_limit[0]
                    
                else:
                    pass
                    
                if if_limit[1] ==True :
                     
                    max = value_limit[1]
                    
                else:
                    pass
                    
            #---------------------------------------
            elif attr in [ 'rz' ,'rotateZ'  ]:
        
                if_limit = mc.transformLimits( obj ,q = True, erz = True )
                
                value_limit = mc.transformLimits( obj ,q = True, rz = True )
                
                if if_limit[0] ==True :
                     
                    min = value_limit[0]
                    
                else:
                    pass
                    
                if if_limit[1] ==True :
                     
                    max = value_limit[1]
                    
                else:
                    pass
            
            #---------------------------------------
            elif attr in [ 'sx' ,'scaleX'  ]:
        
                if_limit = mc.transformLimits( obj ,q = True, erx = True )
                
                value_limit = mc.transformLimits( obj ,q = True, rx = True )
                
                if if_limit[0] ==True :
                     
                    min = value_limit[0]
                    
                else:
                    pass
                    
                if if_limit[1] ==True :
                     
                    max = value_limit[0]
                    
                else:
                    pass
            
            #---------------------------------------
            elif attr in [ 'sy' ,'scaleY'  ]:
        
                if_limit = mc.transformLimits( obj ,q = True, ery = True )
                
                value_limit = mc.transformLimits( obj ,q = True, ry = True )
                
                if if_limit[0] ==True :
                     
                    min = value_limit[0]
                    
                else:
                    pass
                    
                if if_limit[1] ==True :
                     
                    max = value_limit[0]
                    
                else:
                    pass
            
            #---------------------------------------
            elif attr in [ 'sz' ,'scaleZ'  ]:
        
                if_limit = mc.transformLimits( obj ,q = True, erz = True )
                
                value_limit = mc.transformLimits( obj ,q = True, rz = True )
                
                if if_limit[0] ==True :
                     
                    min = value_limit[0]
                    
                else:
                    pass
                    
                if if_limit[1] ==True :
                     
                    max = value_limit[0]
                    
                else:
                    pass
            
            #---------------------------------------
            
            else:
                
                min_value = mc.addAttr( str(obj)+'.'+str(attr) ,q=True ,min =True )     
                max_value = mc.addAttr( str(obj)+'.'+str(attr) ,q=True ,max =True )    
                
                if min_value != None:
                    min = min_value
                if max_value != None:
                    max = max_value
                    
                    
        return (min,max)
    